#pragma once
#include "../../../src/socket/UdpIoServer.h"
#include "../../../src/socket/UdpIoSocket.h"
#include "../../test_type.h"
#include "../../../src/socket/UdpIoServer.h"
#include "../../../src/socket/UdpIoSocket.h"
#include "../../../src/socket/SockTools.h"
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;

class UdpServer
{
public:
	UdpServer(LibTools::SOCKFAMILY::SockFamily domain, const string& ip, DWORD port);
	~UdpServer();

	bool Run();

	void NotifyExit();
protected:
	virtual bool Start() = 0;

	void PostReadMsg(char* buf, size_t size, LibTools::CSockAddr* addr);
	void PostSendMsg(const char* buf, size_t size, LibTools::CSockAddr* addr);

	virtual DWORD CompleteRecvMsg(size_t size, LibTools::CSockAddr* addr, const char* msg) = 0;
	virtual DWORD CompleteSendMsg(size_t size, LibTools::CSockAddr* addr, const char* msg) = 0;

	virtual DWORD GetSocketRecvbufSize() const;
	virtual DWORD GetSocketSendbufSize() const;
private:
	static DWORD CompleteRead(char* data, size_t size, LibTools::CSockAddr* addr, LibTools::CSockError ec, void* invoker);
	static DWORD CompleteSend(char* data, size_t size, LibTools::CSockAddr* addr, LibTools::CSockError ec, void* invoker);
	static DWORD CompletePost(void* invoker);
private:
	LibTools::CUdpIoSocket _udp;
	LibTools::CUdpIoServer _service;
};

